//
// Created by 杜远 on 17/11/11.
//
#include <string.h>
#include <jni.h>
#include <string>

#include "BeaconInterface.h"



#ifdef __cplusplus
extern "C"
{
#endif


JNIEXPORT void JNICALL
Java_com_dy_easyshow_locator_LocatorJni_InitBeaconConfig(JNIEnv *env, jobject thiz, jstring infopath) {
	const char* name_str = env->GetStringUTFChars(infopath, NULL);
	//if (name_str == NULL)
	//{
	//	return;
	//}
	string configfile(name_str);
	InitBeaconConfig(configfile);
	env->ReleaseStringUTFChars(infopath, name_str);
    return;
}

JNIEXPORT void JNICALL
Java_com_dy_easyshow_locator_LocatorJni_BeginSendBeaconData(JNIEnv *env, jobject thiz) {

	BeginSendBeaconData();
    return;
}

JNIEXPORT void JNICALL
Java_com_dy_easyshow_locator_LocatorJni_SendBeaconData(JNIEnv *env, jobject thiz, jstring beaconId,
                                                       jfloat beaconDistance) {
	const char* name_str = env->GetStringUTFChars(beaconId, NULL);
	string name(name_str);
	SendBeaconData(name, beaconDistance);
	env->ReleaseStringUTFChars(beaconId, name_str);
	return;
}

JNIEXPORT void JNICALL
Java_com_dy_easyshow_locator_LocatorJni_EndSendBeaconData(JNIEnv *env, jobject thiz) {
	EndSendBeaconData();
    return;
}

JNIEXPORT jstring JNICALL
Java_com_dy_easyshow_locator_LocatorJni_GetBeaconLocation(JNIEnv *env, jobject thiz) {
	std::string result = GetBeaconLocation();
	LOGI("the name from result is %s", result.c_str());
	return env->NewStringUTF(result.c_str());
}
#ifdef __cplusplus
}
#endif